package com.zcpt.controller.order;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zcpt.order.IAddressService;
import com.zcpt.pojo.order.Address;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/address")
public class AddressController {
    @Reference
    private IAddressService addressService;


    @GetMapping("/queryAll")
    @ApiOperation(value = "收货地址列表",notes = "根据user_id查询收货地址列表信息")
    public String queryAddressList(Model model, Integer user_id){
        List<Address> addressList = addressService.findByUserId(user_id);
        model.addAttribute("addressList", addressList);
        return "pay-address";
    }

    @PostMapping("/addAddress")
    @ApiOperation(value = "添加收货地址",notes = "给指定的user添加收货地址")
    public String addAddress(Model model, Address address){
        addressService.addAddress(address);
        return "forward:/address/queryAll";
    }
}
